package com.th.admin.controller;

import com.th.admin.bean.City;
import com.th.admin.service.CityService;
import com.th.admin.service.UsersService;
import com.th.admin.bean.Users;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author ThreePure
 * @date 2022/4/21 23:25
 * @description: TODO
 * @since 1.8
 */
@Controller
@Slf4j
public class MybatisTestController {
    @Autowired
    private UsersService usersService;

    @Autowired
    private CityService cityService;

    @ResponseBody
    @GetMapping("/users/{id}")
    public Users getUsers(@PathVariable("id") Long id){
        log.info("【Controller】收到的id为{}",id);
        return usersService.getUsers(id);
    }

    @ResponseBody
    @GetMapping("/city")
    public City findById(@RequestParam("id") long id){
        return cityService.findById(id);
    }

    @ResponseBody
    @PostMapping("/city")
    public City insertCity(City city){
        cityService.insertCity(city);
        return city;
    }
}
